package jk.fox.transport.netty.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import jk.fox.serializable.kryo.KryoSerialization;
import jk.fox.serializable.Serialization;
import jk.fox.common.payload.request.RpcRequest;

/**
 * @author cuichao
 * @Description: RpcResponseEncode
 * @Date: create in 2019/12/13 9:32
 */
public class RpcRequestEncode extends MessageToByteEncoder<RpcRequest> {



    private Serialization serialization = new KryoSerialization();


    @Override
    protected void encode(ChannelHandlerContext ctx, RpcRequest msg, ByteBuf out) throws Exception {
        byte[] serialize = serialization.serialize(msg);
        out.writeInt(serialize.length);
        out.writeBytes(serialize);
    }


}
